<extend name="common:commonTemplate" />
<block name="main_content">
<div id="content">
	<div id="content-header">
		<div id="breadcrumb">
			<a class="tip-bottom" href="index.html"
				data-original-title="Go to Home"><i class="icon-home"></i> 首页</a>
			<a href="#">订单</a> <a class="current" href="#">订单列表</a>
		</div>
		
	</div>
	<div class="container-fluid">
		<div class="row-fluid">
			<div class="span12">
				<div class="widget-box">
					<div class="widget-title">
						<span class="icon"> <i class="icon-info-sign"></i>
						</span>
						<h5>搜索条件</h5>
						
					</div>
					<div class="widget-content nopadding">
						<form novalidate="novalidate" id="basic_validate"
							name="basic_validate" action="#" method="post"
							class="form-horizontal">
							<div class="control-group">
								<label class="control-label">订单号</label>
								<div class="controls">
									<input type="text" id="order_id" name="required">
								</div>
							</div>
							<div class="control-group">
								<label class="control-label">推广人编号</label>
								<div class="controls">
									<input type="text" id="promoter_id" name="required">
								</div>
							</div>
							<div class="control-group">
								<label class="control-label">推广人姓名</label>
								<div class="controls">
									<input type="text" id="promoter_name" name="required">
								</div>
							</div>
							<div class="control-group">
								<label class="control-label">订单状态</label>
								<div class="controls">
									<select style="width:220px;" id="order_status">
										<option value="">全部</option>
										<option value="10">已提交</option>
										<option value="21">待支付</option>
										<option value="22">已支付</option>
										<option value="25">物流处理中</option>
										<option value="31">已发货</option>
										<option value="35">已完成</option>
										<option value="51">客户取消</option>
									</select>
								</div>
							</div>
							<div class="control-group">
								<label class="control-label">支付状态</label>
								<div class="controls">
									<select style="width:220px;" id="payment_status">
										<option value="">全部</option>
										<option value="0">未支付</option>
										<option value="1">已支付</option>
										<option value="3">已退款</option>
									</select>
								</div>
							</div>
							<div class="control-group">
								<label class="control-label">订单渠道</label>
								<div class="controls">
									<select style="width:220px;" id="order_type">
										<option value="">全部</option>
										<option value="5">英雄会</option>
										<option value="13">等级品</option>
									</select>
								</div>
							</div>
							<div class="control-group">
								<label class="control-label">订单时间</label>
								<div class="controls">
									<input id="begin_order_date" style="background-color: #fff;border: 1px solid #ccc;box-shadow: 0 1px 1px rgba(0, 0, 0, 0.075) inset;width:217px;color:#555;transition: border 0.2s linear 0s, box-shadow 0.2s linear 0s;" onclick="laydate({istime: true, format: 'YYYY-MM-DD hh:mm:ss'})"> - 
									<input id="end_order_date" style="background-color: #fff;border: 1px solid #ccc;box-shadow: 0 1px 1px rgba(0, 0, 0, 0.075) inset;width:217px;color:#555;transition: border 0.2s linear 0s, box-shadow 0.2s linear 0s;" onclick="laydate({istime: true, format: 'YYYY-MM-DD hh:mm:ss'})">
								</div>
							</div>
							<div class="form-actions">
								<input id="btn_search" type="button" class="btn btn-success" value="搜索">
								<span style="float:right"><a class="btn btn-danger" href="#" id="btn_revenue" />为所有订单分成</a></span>
							</div>
						</form>
					</div>
				</div>
			</div>
		</div>
	
		<div class="row-fluid">
      <div class="span12">
        <div class="widget-box">
          <div class="widget-title"> <span class="icon"> <i class="icon-th"></i> </span>
            <h5>搜索结果</h5>
            <span style="float:right;margin:3px;">
				<a id="exportDJPXls" class="btn btn-primary" href="#">等级品导出发货xls</a>
				<a id="exportDFYXXls" class="btn btn-primary" href="#">东方有线导出发货xls</a>
				<a id="exportXls" class="btn btn-primary" href="#">导出发货xls</a>
			</span>
          </div>
          <div class="widget-content nopadding">
            <table id="search_result" page_index="1" class="table table-bordered table-striped">
              <thead>
                <tr>
                  <th>订单编号</th>
                  <th>推广人编号</th>
                  <th>推广人姓名</th>
                  <th>订单状态</th>
                  <th>订单分成状态</th>
                  <th>支付状态</th>
                  <th>订单金额</th>
                  <th>已分成金额</th>
                  <th>订单时间</th>
                  <th>操作</th>
                </tr>
              </thead>
              <tbody>
                
              </tbody>
            </table>
          </div>
          
        </div>
        
        <div id="paging" class="fg-toolbar ui-toolbar ui-widget-header ui-corner-bl ui-corner-br ui-helper-clearfix">
        	<div class="dataTables_paginate fg-buttonset ui-buttonset fg-buttonset-multi ui-buttonset-multi paging_full_numbers" id="DataTables_Table_0_paginate">
        		<a page_index="1" class="first ui-corner-tl ui-corner-bl fg-button ui-button ui-state-default" tabindex="0" id="DataTables_Table_0_first">首页</a>
        		<a class="previous fg-button ui-button ui-state-default" tabindex="0" id="DataTables_Table_0_previous">上页</a>
        		<span>共<span id="total_count">0</span>条 <span id="curr_page_index">0</span>/<span id="total_page">0</span></span>
       			<a class="next fg-button ui-button ui-state-default" tabindex="0" id="DataTables_Table_0_next">下页</a>
       			<a class="last ui-corner-tr ui-corner-br fg-button ui-button ui-state-default" tabindex="0" id="DataTables_Table_0_last">末页</a>
       			<span>
        			<span><input type="text" style="width:20px;" class="ui-state-default"></span>
        			
        			<a class="fg-button ui-button ui-state-default" tabindex="0">跳转</a>
       			</span>
       		</div>
    	</div>
        

      </div>
    </div>
	
	</div>



</div>
</block>

<block name="js_content">
<script src="/Public/js/laydate/laydate.js"></script> 
<script>
	OrderListPage = {
			'BindEvent': function(){
				//搜索按钮
				$('#btn_search').bind('click', function(){
					var page_index = 1;
					OrderListPage.Search(page_index);
				});
				
				//导出发货xls按钮
				$('#exportXls').bind('click', function(){
					var order_status	= $('#order_status').val();
					var payment_status	= $('#payment_status').val();
					if(order_status != 22 || payment_status != 1){
						alert('如果需导出发货xls，订单状态需选“已支付”，支付状态需选“已支付”');
					}
					
					var lst_param = new Array();
					lst_param.push('promoter_id=' 		+ $('#promoter_id').val());
					lst_param.push('promoter_name='		+ $('#promoter_name').val());
					lst_param.push('order_id=' 			+ $('#order_id').val());
					lst_param.push('order_status=' 		+ order_status);
					lst_param.push('payment_status=' 	+ payment_status);
					lst_param.push('begin_order_date='	+ $('#begin_order_date').val());
					lst_param.push('end_order_date=' 	+ $('#end_order_date').val());
					var str_param = lst_param.join('&');
					
					var export_url = '/order/shipOrderExcel?' + str_param;
					window.open(export_url);
				});


				//导出等级品发货xls按钮
				$('#exportDJPXls').bind('click', function(){
					var export_url = '/order/DJPshipOrderExcel';
					window.open(export_url);
				});

				//导出东方有线发货xls按钮
				$('#exportDFYXXls').bind('click', function(){
					var export_url = '/order/DFYXshipOrderExcel';
					window.open(export_url);
				});
				
				
				//翻页按钮
				$(".first,.previous,.last,.next").bind('click', function(){
					if($(this).hasClass('ui-state-disabled')){
						return false;
					}
					
					var page_index = $(this).attr('page_index');
					if(page_index == undefined){
						page_index = 1;
					}
					
					OrderListPage.Search(page_index);
				});

				//为所有符合条件分成
				$('#btn_revenue').bind('click', function(){
					if(confirm("您确定要为所有符合条件的订单进行分成么？")){
						var order_id = $('#order_id').text();
						var docHeight = document.documentElement.clientHeight;
						layer.open({
							type: 2,
							title: '为所有订单分成',
							fix: true,
							shadeClose: true,
							maxmin: true,
							offset:[(docHeight/2-240)+'px' , ''],
							area : ['auto','450px'],
							content: '/Order/OrderRevenueAction?order_id=' + order_id,
							end: function(){
								window.location.reload();
							}
						});
					}
				});
			},
			'Search': function(page_index){
				var promoter_id		= $('#promoter_id').val();
				var promoter_name	= $('#promoter_name').val();
				var order_id		= $('#order_id').val();
				var order_status	= $('#order_status').val();
				var payment_status	= $('#payment_status').val();
				var order_type		= $('#order_type').val();
				var begin_order_date= $('#begin_order_date').val();
				var end_order_date	= $('#end_order_date').val();

				var page_size		= 20;


				var result = OrderService.SearchOrderList(promoter_id, promoter_name, order_id,
						order_status, payment_status, order_type,
						begin_order_date, end_order_date,
					page_index, page_size);

				if(result.IsSuccess == 0){
					alert(result.ErrorMsg);
					return;
				}
				else{
					
					OrderListPage.FillTable(result.Result.lst_order_en, page_index);
					OrderListPage.SetPageIndex(result.Result.total_page, result.Result.total_count, page_index);
				}
			},
			'FillTable': function(lst_order_en, page_index){
				var html_array = new Array();
				
				if(lst_order_en.length > 0){
					for(var index in lst_order_en){
						var order_en = lst_order_en[index];
						html_array.push('<tr class="odd gradeX">');
						
						html_array.push('<td>' + order_en.order_id + '</td>');
						html_array.push('<td>' + order_en.promoter_id + '</td>');
						html_array.push('<td>' + order_en.promoter_name + '</td>');
						html_array.push('<td>' + order_en.order_status_text + '</td>');
						html_array.push('<td>' + order_en.order_revenue_status_text + '</td>');
						html_array.push('<td>' + order_en.payment_status_text + '</td>');
						html_array.push('<td>' + order_en.order_amount + '</td>');
						html_array.push('<td>' + order_en.revenue_amount + '</td>');
						html_array.push('<td>' + order_en.order_date + '</td>');
						html_array.push('<td><div style="text-align:center;"><a target="_blank" style="color:blue;" href="' + ServerConfig.UrlConfig.order_whaleyinfo_site + 'order/orderdetail?order_id=' + order_en.order_id + '">订单明细</a>&nbsp;&nbsp;&nbsp;&nbsp;');
						html_array.push('<a style="color:blue;" href="/order/detail?order_id=' + order_en.order_id + '">推广订单详情</a></div></td>');
						html_array.push('</tr>');
					}
				}
				else{
					html_array.push('<td style="text-align:center" colspan="10">没查到数据</td>');
				}
				
				var html = html_array.join('\r\n');
				$('#search_result tbody').html('');
				$('#search_result tbody').html(html);
				
				$('#search_result').attr('page_index', page_index);;
			},
			'SetPageIndex': function(total_page, total_count, page_index){
				$('#total_count').text(total_count);
				$('#total_page').text(total_page);
				$('#curr_page_index').text(page_index);
				page_index = parseInt(page_index);
				
				
				
				if(page_index == 1){
					$('#paging .first').addClass('ui-state-disabled');
					$('#paging .previous').addClass('ui-state-disabled');
					$('#paging .first').attr('page_index', 1);
					$('#paging .previous').attr('page_index', 1);
				}
				else{
					$('#paging .first').removeClass('ui-state-disabled');
					$('#paging .previous').removeClass('ui-state-disabled');
					$('#paging .first').attr('page_index', 1);
					$('#paging .previous').attr('page_index', page_index - 1);
				}
		
				if(total_page == page_index){
					$('#paging .last').addClass('ui-state-disabled');
					$('#paging .next').addClass('ui-state-disabled');
					$('#paging .last').attr('page_index', total_page);
					$('#paging .next').attr('page_index', total_page);
				}
				else{
					$('#paging .last').removeClass('ui-state-disabled');
					$('#paging .next').removeClass('ui-state-disabled');
					$('#paging .last').attr('page_index', total_page);
					$('#paging .next').attr('page_index', page_index + 1);
				}
			},
	};


	$(document).ready(function(){
		laydate.skin('danlan');
		OrderListPage.BindEvent();
	});
</script>
</block>